<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    
</head>
<body>
    <button>get</button>
    <button>post</button>

    <script>
        let btns = document.querySelectorAll('button');

        //GET 
        btns[0].onclick = async function(){
            //调用 axios 中方法.
            // let result = await axios.get(url, config);
            let result = await axios.get('http://127.0.0.1/server', {
                params: {
                    a: 100,
                    b: 200
                }
            });
            console.log(result);
        }

        //post
        btns[1].onclick = async function(){
            //调用 axios 中方法.
            // let result = await axios.post(url, data, config);
            let result = await axios.post('http://127.0.0.1/server', {a:100,b:200}, {
                params: {
                    c: 300,
                    d: 400
                },
                headers: {
                    e: 500,
                    f: 600
                }
            });
            console.log(result);
        }
        // delete 请求与 get 请求 参数格式是一样的   axios.delete(url, config)
        // put patch 与 post 请求参数格式是一样的,   axios.put(url, data, config)

    </script>
</body>
</html>